/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gc.cscott.fs;

import com.google.common.collect.ImmutableSet;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

/**
 *
 * @author root
 */
public class CleanupSolutions {

    static final boolean moveFiles = false;
    static final boolean deleteZ1Z4 = false;
    static final boolean deleteBackAndOtherDummy = false;

    public static void main(String[] args) throws IOException {
        for (File userDir : new File("D:/temp/cscott-pack/contest/sources/vsu2").listFiles()) {
            for (File subDir : userDir.listFiles()) {
                if (subDir.isDirectory()) {
                    if (ImmutableSet.of("z1","z2","z3","z4").contains(subDir.getName().toLowerCase())){
                        System.out.println("DETELE "+subDir.getAbsolutePath());
                        if (deleteZ1Z4){
                            FileUtils.deleteDirectory(subDir);
                        }
                    } else if (subDir.getName().toLowerCase().startsWith("z") == false) {
                        System.out.println("DELETE " + subDir.getAbsolutePath());
                        if (moveFiles) {
                            FileUtils.deleteDirectory(subDir);
                        }
                    } else {
                        if (subDir.listFiles().length == 0) {
                            System.out.println("DELETE EMPTY" + subDir.getAbsolutePath());
                            if (moveFiles) {
                                subDir.delete();
                            }
                        } else {
                            for (File file : subDir.listFiles()) {
                                if (file.getName().equalsIgnoreCase("input.txt") ||
                                        file.getName().equalsIgnoreCase("output.txt")) {
                                    System.out.println("DEL FILE: " + file.getAbsolutePath());
                                    if (moveFiles) {
                                        file.delete();
                                    }
                                } else {
                                    if (file.isFile()){
                                        String ext = FilenameUtils.getExtension(file.getName());
                                        if (ext.startsWith("~")||ext.toLowerCase().equals("bak")||ext.toLowerCase().equals("txt")){
                                            System.out.println("DELETE: "+file.getAbsolutePath());
                                            if (deleteBackAndOtherDummy){
                                                file.delete();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }
                } else {
                    System.out.println("DEL FILE: " + subDir.getAbsolutePath());
                    if (moveFiles) {
                        subDir.delete();
                    }
                }
            }
        }

    }
}
